package com.jdz.controller.backend;

import com.jdz.common.ServerResponse;
import com.jdz.pojo.ProjectDetails;
import com.jdz.service.IProjectDetailsService;
import com.jdz.service.IUserService;
import com.jdz.vo.ExportExcelVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * Created by sun
 **/
@Controller
@RequestMapping("/manage/projectDetails")
public class ProjectDetailsManageController {

    @Autowired
    IUserService iUserService;
    @Autowired
    IProjectDetailsService iProjectDetailsService;



//    /**
//     * 项目评审
//     * @param request
//     * @param session
//     * @param reviewnotes 评审分数
//     * @return
//     */
//    @RequestMapping(value = "review.do",method = RequestMethod.POST)
//    @ResponseBody
//    public ServerResponse Review(HttpServletRequest request, HttpSession session, @RequestParam(value = "projectnoList") List<Integer> projectnoList, @RequestParam(value = "reviewnotes") double reviewnotes) {
//
//        UserVo userVo = (UserVo) session.getAttribute(Const.CURRENT_USER);
//        return iProjectDetailsService.Review(projectnoList,userVo.getStuname(),reviewnotes);
//    }


//    /**
//     * 项目审批
//     * @param request
//     * @param session
//     * @param examinestatus 状态
//     * @param examineresult 备注
//     * @return
//     */
//    @RequestMapping(value = "examine.do",method = RequestMethod.POST)
//    @ResponseBody
//    public ServerResponse Examine(HttpServletRequest request, HttpSession session, @RequestParam(value = "projectnoList") List<Integer> projectnoList, @RequestParam(value = "examinestatus") int examinestatus,
//                                  @RequestParam(value = "examineresult")String examineresult) {
//
//        UserVo userVo = (UserVo) session.getAttribute(Const.CURRENT_USER);
//        return iProjectDetailsService.Examine(projectnoList,userVo.getStuname(),examinestatus,examineresult);
//    }
//
    /**
     * 项目统计
     * @return
     */
    @RequestMapping(value = "raceTypeProjectDetailsCount.do",method = RequestMethod.POST)
    @ResponseBody
    public ServerResponse RaceTypeProjectDetailsCount() {
        return iProjectDetailsService.raceTypeProjectDetailsCount();
    }



    /**
     * 项目列表
     * @return
     */
    @RequestMapping(value = "list_product.do",method = RequestMethod.POST)
    @ResponseBody
    public ServerResponse listMyProduct(@RequestParam(value = "pageNum",defaultValue = "1") int pageNum,
                                        @RequestParam(value = "pageSize",defaultValue = "5")int pageSize, @RequestParam(value = "name",required = false) String name, @RequestParam(value = "startTime",required = false)String startTime,
                                        @RequestParam(value = "stopTime",required = false)String stopTime, @RequestParam(value = "projectType",required = false) String projectType,
                                        @RequestParam(value = "stuInstitute",required = false)String stuInstitute, @RequestParam(value = "examineStatus",required = false)Integer examineStatus
            , @RequestParam(value = "time_sort",defaultValue = "0") int time_sort){
        return iProjectDetailsService.listProduct(pageNum,pageSize,name,startTime,stopTime,projectType,stuInstitute,examineStatus,time_sort);
    }


    /**
     * 删除项目信息
     * @return
     */
    @RequestMapping(value = "delete.do",method = RequestMethod.POST)
    @ResponseBody
    public ServerResponse delete(@RequestParam(value = "projectnoList") List<Integer> projectnoList) {

        return iProjectDetailsService.delete(projectnoList);
    }


    /**
     * 锁定项目信息
     * @return
     */
    @RequestMapping(value = "Lock.do",method = RequestMethod.POST)
    @ResponseBody
    public ServerResponse Lock(@RequestParam(value = "projectnoList") List<Integer> projectnoList) {

        return iProjectDetailsService.Lock(projectnoList);
    }

    /**
     * 解锁项目信息
     * @return
     */
    @RequestMapping(value = "DebLock.do",method = RequestMethod.POST)
    @ResponseBody
    public ServerResponse DebLock(@RequestParam(value = "projectnoList") List<Integer> projectnoList) {

        return iProjectDetailsService.Deblock(projectnoList);
    }

    /**
     * 修改项目信息
     * @returnt
     */
    @RequestMapping(value = "update.do",method = RequestMethod.POST)
    @ResponseBody
    public ServerResponse update(ProjectDetails projectDetails) {

        return iProjectDetailsService.update(projectDetails);
    }

    /**
     * 设置为优秀项目
     * @returnt
     */
    @RequestMapping(value = "set_excellent_works.do",method = RequestMethod.POST)
    @ResponseBody
    public ServerResponse setExcellentWorks(@RequestParam(value = "projectnoList") List<Integer> projectnoList) {

        return iProjectDetailsService.setExcellentWorks(projectnoList);
    }


    /**
     * 删除优秀项目
     * @returnt
     */
    @RequestMapping(value = "del_excellent_works.do",method = RequestMethod.POST)
    @ResponseBody
    public ServerResponse delExcellentWorks(@RequestParam(value = "projectnoList") List<Integer> projectnoList) {

        return iProjectDetailsService.delExcellentWorks(projectnoList);
    }


    /**
     * 项目详情
     * @param session
     * @param projectno
     * @return
     */
    @RequestMapping(value = "details_productt.do",method = RequestMethod.GET)
    @ResponseBody
    public ServerResponse detailsProduct(HttpSession session, Integer projectno){
        return iProjectDetailsService.detailsProductAdmin(session,projectno);
    }


    /**
     * 导出项目信息exel表
     * @param request
     * @param response
     * @param session
     * @param projectnoList
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "export_busInfo.do",method = RequestMethod.GET)
    @ResponseBody
    public byte[] exportBusInfo(HttpServletRequest request, HttpServletResponse response, HttpSession session , @RequestParam(value = "projectnoList[]",required = false) List<Integer> projectnoList) throws Exception {

        ExportExcelVo<byte[]> exportExcelVo = iProjectDetailsService.exportBusInfo(projectnoList,request,response);
        if(exportExcelVo.getFileName()==null||exportExcelVo.getServerResponse()==null){
            return null;

        }

        response.setHeader("Content-Disposition", "attachment;filename="+exportExcelVo.getFileName());
        ServerResponse<byte[]> serverResponse = exportExcelVo.getServerResponse();
        return serverResponse.getData();

    }

    /**
     * 首页统计
     * @returnt
     */
    @RequestMapping(value = "index_count.do",method = RequestMethod.POST)
    @ResponseBody
    public ServerResponse IndexCount() {

        return iProjectDetailsService.IndexCount();
    }

    /**
     * 项目评分结果列表
     * @return
     */
    @RequestMapping(value = "list_product_result.do",method = RequestMethod.POST)
    @ResponseBody
    public ServerResponse listProductResult(@RequestParam(value = "pageNum",defaultValue = "1") int pageNum,
                                            @RequestParam(value = "pageSize",defaultValue = "5")int pageSize,
                                            @RequestParam(value = "racetypesamsarano")Integer racetypesamsarano,
                                            @RequestParam(value = "weightFrom",defaultValue = "0")Integer weightFrom){
        return iProjectDetailsService.listProductResult(pageNum,pageSize,racetypesamsarano, weightFrom);
    }

    /**
     * 导出项目评分结果列表exel表
     * @param request
     * @param response
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "result_export_busInfo.do",method = RequestMethod.GET)
    @ResponseBody
    public byte[] resultExportBusInfo(Integer racetypesamsarano,Integer weightFrom,HttpServletRequest request, HttpServletResponse response) throws Exception {

        ExportExcelVo<byte[]> exportExcelVo = iProjectDetailsService.listProductResultInfor( racetypesamsarano, weightFrom,request,response);
        if(exportExcelVo.getFileName()==null||exportExcelVo.getServerResponse()==null){
            return null;
        }

        response.setHeader("Content-Disposition", "attachment;filename="+exportExcelVo.getFileName());
        ServerResponse<byte[]> serverResponse = exportExcelVo.getServerResponse();
        return serverResponse.getData();

    }

}
